package woniuxy.commons;/*
 * @Author: Tiangle
 * @Date:   {DATE}
 * @TIME:   {TIME}
 * @Project_Name: {PROJECT_NAME}
 * @Package_Name: {PACKAGE_NAME}
 */

import woniuxy.model.City;
import woniuxy.model.Country;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class PrintCitys {
    public static void pc(HttpServletResponse resp, Country country) throws IOException {
        List<City> cities = country.getCities();
        String str = "<table border=\"1px\" bordercolor=\"black\" cellspacing=\"0px\" cellpadding=\"0px\">"+
			"<tr>"+ "<th colspan=\"5\">" + country.getName()+ "国家城市一览</th>"+
			"</tr><tr><td width=\"60\" align=\"center\">城市Id</td>"+
                "<td width=\"120\" align=\"center\">城市名</td>"+
				"<td width=\"120\" align=\"center\">国家代码</td>"+
				"<td width=\"120\" align=\"center\">区域</td>"+
				"<td width=\"120\" align=\"center\">人口</td>"+
			"</tr>";
        String td= "<td>";
        String td2 = "</td>";
        for(int i=0;i<cities.size();i++){
            str+="<tr>";
            str+=td+cities.get(i).getID()+td2;
            str+= td + cities.get(i).getName()+td2;
            str+= td + cities.get(i).getCountryCode() + td2;
            str+= td + cities.get(i).getDistrict() + td2;
            str+= td + cities.get(i).getPopulation() + td2;
            str+="</tr>";

        }

        str+="</table>";
        resp.getWriter().write(str);
    }

    public static void pc2(HttpServletResponse resp, List<City> cities) throws IOException {
        String str = "<table border=\"1px\" bordercolor=\"black\" cellspacing=\"0px\" cellpadding=\"0px\">"+
                "<tr>"+ "<th colspan=\"5\">" +  "所以国家城市一览</th>"+
                "</tr><tr><td width=\"60\" align=\"center\">城市Id</td>"+
                "<td width=\"120\" align=\"center\">城市名</td>"+
                "<td width=\"120\" align=\"center\">国家代码</td>"+
                "<td width=\"120\" align=\"center\">区域</td>"+
                "<td width=\"120\" align=\"center\">人口</td>"+
                "</tr>";
        String td= "<td>";
        String td2 = "</td>";
        for(int i=0;i<cities.size();i++){
            str+="<tr>";
            str+=td+cities.get(i).getID()+td2;
            str+= td + cities.get(i).getName()+td2;
            str+= td + cities.get(i).getCountryCode() + td2;
            str+= td + cities.get(i).getDistrict() + td2;
            str+= td + cities.get(i).getPopulation() + td2;
            str+="</tr>";

        }

        str+="</table>";
        resp.getWriter().write(str);
    }
}
